package com.tzbank.back.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tzbank.back.service.LotteryDeployService;
import com.tzbank.entity.backstage.LotteryDeploy;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

import lombok.extern.slf4j.Slf4j;

/**
 *  抽奖管理配置
 * @author 蔡宇钿
 *2018年6月1日
 */
@Slf4j
@RestController
public class LotteryDeployController {

	@Autowired
	private LotteryDeployService lotteryDeployService;
	
	@PostMapping(value = "getlistLottery")
	public Map<String, Object> getlistLottery(@RequestParam(required = false) String activename) {
		Map<String, Object> map = new HashMap<>();
		try {
			if (StringUtils.isBlank(activename)) {
				map=lotteryDeployService.getlistLottery();
			}else {
				map=lotteryDeployService.getlistBylotteryactivname(activename);
			}
			log.info("map========"+ map );
			return map;
		} catch (Exception e) {
			log.error("LotteryDeployController getlistLottery: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	@PostMapping(value = "addLottery")
	// 增加配置
	public Map<String, Object> addLottery(HttpServletRequest request,@RequestBody LotteryDeploy lotteryDeploy) {
		try {
			return this.lotteryDeployService.addLottery(lotteryDeploy);
		} catch (Exception e) {
			log.error("LotteryDeployController addLottery: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	@PostMapping(value = "modifyBylotteryautoId")
	// 更新配置
	public Map<String, Object> modifyBylotteryautoId(HttpServletRequest request, @RequestBody LotteryDeploy lotteryDeploy) {
		try {
			return this.lotteryDeployService.modifyBylotteryautoId(lotteryDeploy);
		} catch (Exception e) {
			log.error("LotteryDeployController modifyBylotteryautoId: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	@PostMapping(value = "deleteBylottauto")
	// 通过逻辑方式实现删除
	public Map<String, Object> deleteBylottauto(HttpServletRequest request, @RequestBody LotteryDeploy lotteryDeploy) {
		try {
			return this.lotteryDeployService.deleteBylottauto(lotteryDeploy);
		} catch (Exception e) {
			log.error("LotteryDeployController deleteBylottauto: ", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}
}
